"""
中间件
"""
from fastapi import Request
from fastapi.middleware.cors import CORSMiddleware

from .main import app


# @app.middleware("http")
# async def add_process_time_header(request: Request, call_next):
#     response = await call_next(request)
#     response.headers["Access-Control-Allow-Origin"] = "http://192.168.31.82:8081"
#     response.headers["Access-Control-Allow-Headers"] = "*"
#     response.headers["Access-Control-Allow-Methods"] = "*"
#     response.headers["Access-Control-Allow-Credentials"] = "true"
#     return response

app.add_middleware(CORSMiddleware,
                   allow_origins=[
                       # "http://192.168.31.82:8081",
                       # "http://192.168.31.82",
                       "*"
                   ],
                   allow_credentials=True,
                   allow_methods=["*"],
                   allow_headers=["*"],
                   )